/**
 * ------------------------------------------------------------------
 * @project [fuping background management system]
 * @module common function
 * @date 2017-11-09
 * @author Arthur - caiwen
 * ------------------------------------------------------------------
 */

/**
 * @method [翻页滚动条置顶方法]
 * @method goScrollTop
 * @date 2018-02-08
 * @author Arthur - caiwen
 * @parameter el 当前点击元素
 */
/*-- 翻页滚动条置顶 --*/
function goScrollTop (el) {
    el.parents(".page").prev("div").scrollTop(0)
}


/**
 * @method [分页方法]
 * @method PagingMethods
 * @date 2017-11-11
 * @author Arthur - caiwen
 * @parameter pageNo 当前第几页数
 * @parameter pageSize 每页行数
 * @parameter pageCount 数据总页数
 * @parameter rowCount 数据总条数
 * @parameter data 接口返回数据
 * @parameter getList 页面渲染方法
 */
/*-- 分页方法 --*/
function PagingMethods(pageNo, pageSize, data, getList) {
    //分页-左边下拉框组
    if (!data.result.rowCount) { //data.result.rowCount 分页数据总条数
        pageCount = 0;
    } else {
        pageCount = data.result.pageCount //pageCount 分页数据总页数
    }
    var pageCountArr = [] //pageCountArr 总页数数组
    if (data.result.pageCount <= 1) { //若只有一页
        $('#pageBtn').hide() //pageBtn 分页按钮组
    } else {
        $('#pageBtn').show()
    }
    for (var i = 1; i <= data.result.pageCount; i++) {
        pageCountArr.push({ //循环添加pageCount,pageCountArr为{pageCount: i}对象数组
            pageCount: i
        })
    }
    data.result.pageCount = pageCountArr

    mccms.getHbs({ //填充-分页模板
        "local": true,
        "hbsName": "page",
        "container": $("#pageContainer"),
        "data": data.result,
        "callback": function() {
            if (!data.result.rowCount) { //处理IE兼容性样式问题 ==》 无数据时填充一个空option
                $('#pageCount').html('<option></option>')
            }

            $('#pageSize').val(pageSize)
            $('#pageCount').val(pageNo)
            $('#pageSize').change(function() {
                goScrollTop($(this))
                pageNo = 1
                pageSize = this.value
                getList(1, pageSize)
            })
            $('#pageCount').change(function() {
                goScrollTop($(this))
                pageNo = Number(this.value)
                getList(pageNo, pageSize)
            })
        }
    });

    //分页-右边按钮组
    $('#firstPage').off().click(function() { //首页
        goScrollTop($(this))
        if (pageNo === 1) {
            return false
        }
        pageNo = 1
        $('#pageCount').val(pageNo)
        getList(pageNo, pageSize)
    })
    $('#prevPage').off().click(function() { //上一页
        goScrollTop($(this))
        if (pageNo <= 1) {
            return false
        }
        pageNo--
        getList(pageNo, pageSize)
    })
    $('#nextPage').off().click(function() { //下一页  
        goScrollTop($(this)) 

        if (pageNo >= pageCount) {
            return false
        }
        pageNo++;
        getList(pageNo, pageSize)
    })
    $('#lastPage').off().click(function() { //尾页
        goScrollTop($(this))
        if (pageNo === pageCount) {
            return false
        }
        pageNo = pageCount
        $('#pageCount').val(pageNo)
        getList(pageNo, pageSize)
    })
}

/**
 * @method [乡和村下拉选择方法]
 * @method cryAndNameChange
 * @date 2017-11-11
 * @author Arthur - caiwen
 * @parameter cry 乡
 * @parameter name 村
 */
/*-- 乡和村下拉选择方法 --*/
var nameValAll; //村的中文名全局变量
function cryAndNameChange() {
    //乡选中加载村数据
    $("#cry").change(function() {
        cryId = $(this).find("option:checked").attr("id");
        cryAreaCode = $(this).find("option:checked").attr("data-number");
        /*cryVal = $(this).find("option:checked").val()*/
        $("#h-cry").val(cryAreaCode); //乡的地区编码值
        $("#h-name").val("") //清空村值
        mccms.ajax({ //地区查询API
            "url": "/area/findarea",
            "cache": false,
            "method": "POST",
            "data": {
                "fatherId": cryId
            },
            success: function(data) { //处理数据动态生成下拉option
                var naturalsHtml = '<option value="" selected>请选择</option>';
                for (var i = 0; i < data.result.length; i++) {
                    naturalsHtml += '<option data-number="' + data.result[i].areaCode + '" id="' + data.result[i].id + '" value="' + data.result[i].area + '">' + data.result[i].area + '</option>';
                }
                $("#name").html(naturalsHtml); //塞入村下拉框

            }
        });
    });

    //村选中加载村数据
    $("#name").change(function() {
        s_name_id = $(this).find("option:checked").attr("data-number");
        $("#h-name").val(s_name_id);
        nameValAll = $(this).find("option:checked").val(); //获取乡选中值，如果不获取，页面查询后，页面该值显示为空
        
        cryAndNameChange();

    });
    return nameValAll
}

/**
 * @method [乡和村下拉选择方法2-带参数的]
 * @method cryAndNameChange
 * @date 2017-11-11
 * @author Arthur - caiwen
 * @parameter cry 乡
 * @parameter name 村
 */
/*-- 乡和村下拉选择方法 --*/
function cryAndNameChange2() {
    //乡选中加载村数据
    $("#cry").change(function() {
        cryId = $(this).find("option:checked").attr("id");
        cryAreaCode = $(this).find("option:checked").attr("data-number");
        $("#h-cry").val(cryAreaCode); //乡的地区编码值
        mccms.ajax({ //地区查询API
            "url": "/area/findarea",
            "cache": false,
            "method": "POST",
            "data": {
                "fatherId": cryId
            },
            success: function(data) { //处理数据动态生成下拉option
                var naturalsHtml = '<option value="" selected>请选择</option>';
                for (var i = 0; i < data.result.length; i++) {
                    naturalsHtml += '<option data-number="' + data.result[i].areaCode + '" id="' + data.result[i].id + '" value="' + data.result[i].area + '">' + data.result[i].area + '</option>';
                }
                $("#name").html(naturalsHtml); //塞入村下拉框
            }
        });
    });

    //村选中加载村数据
    $("#name").change(function() {
        nameVal = $(this).find("option:checked").val(); //获取乡选中值，如果不获取，页面查询后，页面该值显示为空  
        s_name_id = $(this).find("option:checked").attr("data-number");
        $("#h-name").val(s_name_id);
    });
}
/**
 * ------------------------------------------------------------------
 * @project [fuping background management system]
 * @module inquireBill - 账表查询模块
 * @date 2017-11-09
 * @author Arthur - caiwen
 * ------------------------------------------------------------------
 */

/**
 * @submenu [贫困户查询]
 * @Method povertyStrickenInquire
 * @date 2017-11-13
 * @author Arthur - caiwen
 * @parameter main 主页面容器
 * @parameter mainList 主页面hbs模板
 * @parameter $("#searchForm").serialize() 查询时表单序列化参数
 */
/*--贫困户查询--*/
function povertyStrickenInquire() {
    // 变量声明
    var main = $('#mainCon'),
        cryVal = s_cry, //乡的选中
        nameVal = s_name, //村的选中
        pageNo = 1, //当前第1页
        pageSize = 10, //每页10行
        pageCount = null,
        backFrom, //进入编辑、查看页面时，主页面的查询条件
        getList = function(pageNo, pageSize, checkType) { //getList() 主页面渲染
            //乡和村下拉选择
            nameVal = cryAndNameChange()
            areaSelected(cryVal, nameVal, checkType, function() { //areaSelected() 权限控制方法
                if (sessionStorage.getItem('backId') == 1) { //从编辑、查看页面返回时，根据原先的查询条件查询
                    backFrom = sessionStorage.getItem('from')
                } else { //刷新时，重置查询条件
                    backFrom = $("#searchForm").serialize() + "&pageNo=" + pageNo + "&pageSize=" + pageSize
                }
                mccms.ajax({ //贫困户查询API
                    "url": "/poorFa/queryPoorHFamily",
                    "cache": false,
                    "method": "POST",
                    "data": backFrom,
                    "success": function(data) {
                        var data = data;
                        /*实际家庭成员数模块 start*/
                        for(var i = 0; i < data.result.resultList.length; i++){
                            data.result.resultList[i].familyLen = 0;
                            var familyLen = 0; //实际家庭成员数量
                            for(var j = 0; j < data.result.resultList[i].family.length; j++){
                                if(data.result.resultList[i].family[j].isDel == "0"){
                                    familyLen ++ ;
                                    data.result.resultList[i].familyLen = familyLen;
                                }
                            }
                        }

                        /*实际家庭成员数模块 end*/
                        mccms.getHbs({
                            "local": true,
                            "hbsName": "mainList",
                            "container": $("#tbody"),
                            "data": data.result,
                            "callback": function() {
                                if (sessionStorage.getItem('backId') == 1) { //查看编辑页面返回，回显原先的查询页码和每页数据条
                                    var pageNo3 = sessionStorage.getItem('pageNo2'),
                                        pageSize3 = sessionStorage.getItem('pageSize2'),
                                        prevFrom = JSON.parse(sessionStorage.getItem('prevFrom'));
                                    //显示原先的查询条件
                                    for (var i in prevFrom) {
                                        if(i == "cry"){
                                            $('#cry option').each(function(){
                                                if($(this).val() == prevFrom[i]){
                                                    $(this).attr('selected','selected')
                                                    $("#h-cry").val($(this).attr("data-number")) //乡code值回显
                                                }
                                            })
                                            cryVal = prevFrom[i]  //乡赋值，用于分页点击之后回显
                                        }
                                        else if (i == 'name') {
                                            /*$('#' + i).find('option:selected').text(prevFrom[i])*/
                                            $('#name option').each(function(){
                                                if($(this).val() == prevFrom[i]){
                                                    $(this).attr('selected','selected')
                                                    $("#h-name").val($(this).attr("data-number")) //村code值回显
                                                }
                                            })
                                            nameVal = prevFrom[i]
                                        } else {
                                            $('#' + i).val(prevFrom[i])
                                        }
                                    }
                                    //分页方法
                                    PagingMethods(pageNo3, pageSize3, data, getList);

                                } else {
                                    //分页方法
                                    PagingMethods(pageNo, pageSize, data, getList);
                                }
                                //删除从查看、编辑页面返回的标记,不然刷新会有问题
                                sessionStorage.removeItem("backId");
                                //点击数据项添加背景色
                                tdAddBg('tbody')

                                $('#cry').change(function(event) {
                                    /* Act on the event */
                                    cryVal = $(this).find('option:selected').val() //获取乡选择，用于查询条件回显，若不获取，条件会被重置
                                });

                            }
                        });
                    }
                })
            });
        };


    //时间插件初始化
    laydate.render({
        elem: '#year', //指定元素
        type: 'year'
    })


    // 流程
    ThisYear(); //当前年
    main.on('click', '.detail_btn', function() { //查看
        var id = $(this).parents('td').attr('id');
        mccms.goTo("povertyStrickenInquire", "povertyStrickenEdit", { "id": id, "operatedState": 1, "inquire": 1, "detail": 1 }); //跳转至《扶贫对象管理》的《贫困户管理》的查看页。inquire: 1,表示查询账表
    });
    main.on('click', '.queryBtn', function() { //查询
        getList(pageNo, pageSize, 'true')
    });
    main.on('click', ".export_btn", function() { //导出功能
        location.href = "poorFa/exportPoorFamilyZ?" + $("#searchForm").serialize();
    });
    //进入查看页面前，保留查询条件
    main.on('click', '.save_from', function() {
        var pageNo2 = $('#pageCount').val(),
            pageSize2 = $('#pageSize').val()
        prevFrom = {
            "year": $('#year').val(),
            "cry": $('#cry').val(),
            "name": $('#name').val(),
            "attribute": $('#attribute').val(),
            "standard": $('#standard').val(),
            "poverty": $('#poverty').val(),
            "poorName": $('#poorName').val(),
            "idNumber": $('#idNumber').val()
        };
        sessionStorage.setItem('pageNo2', pageNo2)
        sessionStorage.setItem('pageSize2', pageSize2)
        sessionStorage.setItem('from', $("#searchForm").serialize() + "&pageNo=" + pageNo2 + "&pageSize=" + pageSize2)
        sessionStorage.setItem('prevFrom', JSON.stringify(prevFrom))

    })
    getList(pageNo, pageSize);

}

/**
 * @submenu [贫困村查询]
 * @Method poorVillageInquire
 * @date 2017-11-10
 * @author Arthur - caiwen
 * @parameter main 主页面容器
 * @parameter mainList 主页面hbs模板
 * @parameter $("#searchForm").serialize() 查询时表单序列化参数
 */
/*--贫困村查询--*/
function poorVillageInquire() {
    // 变量声明
    var main = $('#mainCon'),
        cryVal = s_cry, //乡的选中
        nameVal = s_name, //村的选中
        pageNo = 1, //当前第1页
        pageSize = 10, //每页10行
        pageCount = null, //总页数
        backFrom, //进入编辑、查看页面时，主页面的查询条件
        getList = function(pageNo, pageSize, checkType) { //getList() 主页面渲染
            areaSelected(cryVal, nameVal, checkType, function() { //areaSelected() 权限控制方法
                if (sessionStorage.getItem('backId') == 1) { //从编辑、查看页面返回时，根据原先的查询条件查询
                    backFrom = sessionStorage.getItem('from')
                } else { //刷新时，重置查询条件
                    backFrom = $("#searchForm").serialize() + "&pageNo=" + pageNo + "&pageSize=" + pageSize
                }
                mccms.ajax({ //贫困村查询API
                    "url": "/poorVi/queryPoVague",
                    "cache": false,
                    "method": "POST",
                    "data": backFrom,
                    "success": function(data) {
                        var data = data;
                        mccms.getHbs({
                            "local": true,
                            "hbsName": "mainList",
                            "container": $("#tbody"),
                            "data": data.result,
                            "callback": function() {
                                if (sessionStorage.getItem('backId') == 1) { //查看编辑页面返回，回显原先的查询页码和每页数据条
                                    var pageNo3 = sessionStorage.getItem('pageNo2'),
                                        pageSize3 = sessionStorage.getItem('pageSize2'),
                                        prevFrom = JSON.parse(sessionStorage.getItem('prevFrom'));
                                    //显示原先的查询条件
                                    for (var i in prevFrom) {
                                        if(i == "cry"){
                                            $('#cry option').each(function(){
                                                if($(this).val() == prevFrom[i]){
                                                    $(this).attr('selected','selected')
                                                    $("#h-cry").val($(this).attr("data-number")) //乡code值回显
                                                }
                                            })
                                            cryVal = prevFrom[i]  //乡赋值，用于分页点击之后回显
                                        }
                                        else if (i == 'name') {
                                            /*$('#' + i).find('option:selected').text(prevFrom[i])*/
                                            $('#name option').each(function(){
                                                if($(this).val() == prevFrom[i]){
                                                    $(this).attr('selected','selected')
                                                    $("#h-name").val($(this).attr("data-number")) //村code值回显
                                                }
                                            })
                                            nameVal = prevFrom[i]
                                        } else {
                                            $('#' + i).val(prevFrom[i])
                                        }
                                    }
                                    //分页方法
                                    PagingMethods(pageNo3, pageSize3, data, getList);

                                } else {
                                    //分页方法
                                    PagingMethods(pageNo, pageSize, data, getList);
                                }
                                //删除从查看、编辑页面返回的标记,不然刷新会有问题
                                sessionStorage.removeItem("backId");

                                //点击数据项添加背景色
                                tdAddBg('tbody')

                                //乡回显
                                $('#cry').change(function(event) {
                                    /* Act on the event */
                                    cryVal = $(this).find('option:selected').val() //获取乡选择，用于查询条件回显，若不获取，条件会被重置
                                })
                                //村回显
                                $('#name').change(function(event) {
                                    /* Act on the event */
                                    nameVal = $(this).find('option:selected').val() //获取村选择，用于查询条件回显，若不获取，条件会被重置
                                })



                            }
                        });
                    }
                })
            });
        };
    //时间插件初始化
    laydate.render({
        elem: '#year', //指定元素
        type: 'year'
    })
    //乡和村下拉选择
    cryAndNameChange()

    // 流程
    ThisYear(); //当前年
    main.on('click', '.detail_btn', function() { //查看
        var id = $(this).parents('td').attr('id');
        mccms.goTo("poorVillageInquire", "poorVillageEdit", { "id": id, "operated": 1, "inquire": 1 }); //跳转至《扶贫对象管理》的《贫困村管理》的查看页。inquire: 1,表示查询账表
    });
    main.on('click', '.queryBtn', function() { //查询
        getList(pageNo, pageSize, 'true')
    });
    main.on('click', ".export_btn", function() { //导出功能
        location.href = "poorVi/exportPoVillageZ?" + $("#searchForm").serialize();
    });
    //进入编辑、查看页面前，保留查询条件
    main.on('click', '.save_from', function() {
        var pageNo2 = $('#pageCount').val(),
            pageSize2 = $('#pageSize').val()
        prevFrom = {
            "year": $('#year').val(),
            "cry": $('#cry option:selected').val(),
            "h-cry":$('#h-cry').val(),
            "name": $('#name option:selected').val(),
            "h-name":$('#h-name').val(),
            "nature": $('#nature option:selected').val()
        };
        sessionStorage.setItem('pageNo2', pageNo2)
        sessionStorage.setItem('pageSize2', pageSize2)
        sessionStorage.setItem('from', $("#searchForm").serialize() + "&pageNo=" + pageNo2 + "&pageSize=" + pageSize2)
        sessionStorage.setItem('prevFrom', JSON.stringify(prevFrom))

    })
    getList(pageNo, pageSize)

}

/**
 * @submenu [自然村查询]
 * @Method naturalVillageInquire
 * @date 2017-11-13
 * @author Arthur - caiwen
 * @parameter main 主页面容器
 * @parameter mainList 主页面hbs模板
 * @parameter $("#searchForm").serialize() 查询时表单序列化参数
 */
/*-- 自然村查询 --*/
function naturalVillageInquire() {
    // 变量声明
    var main = $('#mainCon'),
        cryVal = s_cry, //乡的选中
        nameVal = s_name, //村的选中
        pageNo = 1, //当前第1页
        pageSize = 10, //每页10行
        pageCount = null,
        backFrom, //进入编辑、查看页面时，主页面的查询条件
        countryName, //村名
        getList = function(pageNo, pageSize, checkType) { //getList() 主页面渲染
            areaSelected(cryVal, nameVal, checkType, function() { //areaSelected() 权限控制方法
                if (sessionStorage.getItem('backId') == 1) { //从编辑、查看页面返回时，根据原先的查询条件查询
                    backFrom = sessionStorage.getItem('from')
                } else { //刷新时，重置查询条件
                    backFrom = $("#searchForm").serialize() + "&pageNo=" + pageNo + "&pageSize=" + pageSize
                }
                mccms.ajax({ //自然村查询API
                    "url": "/poorVi/queryNaVague",
                    "cache": false,
                    "method": "POST",
                    "data": backFrom,
                    "success": function(data) {
                        var data = data;
                        mccms.getHbs({
                            "local": true,
                            "hbsName": "mainList",
                            "container": $("#tbody"),
                            "data": data.result,
                            "callback": function() {
                                if (sessionStorage.getItem('backId') == 1) { //查看编辑页面返回，回显原先的查询页码和每页数据条
                                    var pageNo3 = sessionStorage.getItem('pageNo2'),
                                        pageSize3 = sessionStorage.getItem('pageSize2'),
                                        prevFrom = JSON.parse(sessionStorage.getItem('prevFrom'));
                                    //显示原先的查询条件
                                    for (var i in prevFrom) {
                                        if(i == "cry"){
                                            $('#cry option').each(function(){
                                                if($(this).val() == prevFrom[i]){
                                                    $(this).attr('selected','selected')
                                                    $("#h-cry").val($(this).attr("data-number")) //乡code值回显
                                                }
                                            })
                                            cryVal = prevFrom[i]  //乡赋值，用于分页点击之后回显
                                        }
                                        else if (i == 'name') {
                                            /*$('#' + i).find('option:selected').text(prevFrom[i])*/
                                            $('#name option').each(function(){
                                                if($(this).val() == prevFrom[i]){
                                                    $(this).attr('selected','selected')
                                                    $("#h-name").val($(this).attr("data-number")) //村code值回显
                                                }
                                            })
                                            nameVal = prevFrom[i]
                                        } else {
                                            $('#' + i).val(prevFrom[i])
                                        }
                                    }
                                    //分页方法
                                    PagingMethods(pageNo3, pageSize3, data, getList);

                                } else {
                                    //分页方法
                                    PagingMethods(pageNo, pageSize, data, getList);
                                }
                                //删除从查看、编辑页面返回的标记,不然刷新会有问题
                                sessionStorage.removeItem("backId");


                                //点击数据项添加背景色
                                tdAddBg('tbody')
                                //乡回显
                                $('#cry').change(function(event) {
                                    /* Act on the event */
                                    cryVal = $(this).find('option:selected').val() //获取乡选择，用于查询条件回显，若不获取，条件会被重置
                                   
                                })
                                //村回显
                                $('#name').change(function(event) {
                                    /* Act on the event */
                                    nameVal = $(this).find('option:selected').val() //获取村选择，用于查询条件回显，若不获取，条件会被重置
                                })

                            }
                        });
                    }
                })
            });
        };
    //时间插件初始化
    laydate.render({
        elem: '#year', //指定元素
        type: 'year'
    })

    //乡和村下拉选择
    cryAndNameChange()

    // 流程 
    ThisYear(); //当前年 
    main.on('click', '.detail_btn', function() { //查看
        var id = $(this).parents('td').attr('id');
        mccms.goTo("naturalVillageInquire", "naturalVillageEdit", { "id": id, "operated": 1, "inquire": 1 }); //跳转至《扶贫对象管理》的《自然村管理》的查看页。inquire: 1,表示查询账表
    });
    main.on('click', '.queryBtn', function() { //查询
        getList(pageNo, pageSize, 'true')
    });
    main.on('click', ".export_btn", function() { //导出功能
        location.href = "poorVi/exportNaVillageZ?" + $("#searchForm").serialize();
    });
    //进入编辑、查看页面前，保留查询条件
    main.on('click', '.save_from', function() {
        var pageNo2 = $('#pageCount').val(),
            pageSize2 = $('#pageSize').val()
        prevFrom = {
            "cry": $('#cry').val(),
            "name": $('#name').val(),
            "h-cry": $('#h-cry').val(),
            "h-name": $('#h-name').val()
        };
        sessionStorage.setItem('pageNo2', pageNo2)
        sessionStorage.setItem('pageSize2', pageSize2)
        sessionStorage.setItem('from', $("#searchForm").serialize() + "&pageNo=" + pageNo2 + "&pageSize=" + pageSize2)
        sessionStorage.setItem('prevFrom', JSON.stringify(prevFrom))

    })
    getList(pageNo, pageSize);

}

/**
 * @submenu [贫困村变更查询]
 * @Method povertyVillageMesInquire
 * @date 2017-11-15
 * @author Arthur - caiwen
 * @parameter main 主页面容器
 * @parameter mainList 主页面hbs模板
 * @parameter $("#searchForm").serialize() 查询时表单序列化参数
 */
/*--贫困村变更查询--*/
function povertyVillageMesInquire() {
    // 变量声明
    var main = $('#mainCon'),
        cryVal = s_cry, //乡的选中
        nameVal = s_name, //村的选中
        pageNo = 1, //当前第1页
        pageSize = 10, //每页10行
        pageCount = null,
        backFrom, //进入编辑、查看页面时，主页面的查询条件
        getList = function(pageNo, pageSize, checkType) { //getList() 主页面渲染

            areaSelected(cryVal, nameVal, checkType, function() { //areaSelected() 权限控制方法
                if (sessionStorage.getItem('backId') == 1) { //从编辑、查看页面返回时，根据原先的查询条件查询
                    backFrom = sessionStorage.getItem('from')
                } else { //刷新时，重置查询条件
                    backFrom = $("#searchForm").serialize() + "&pageNo=" + pageNo + "&pageSize=" + pageSize
                }
                mccms.ajax({ //贫困村变更查询API
                    "url": "/dequCon/queryDequeue",
                    "cache": false,
                    "method": "POST",
                    "data": backFrom,
                    "success": function(data) {
                        var data = data;
                        mccms.getHbs({
                            "local": true,
                            "hbsName": "mainList",
                            "container": $("#tbody"),
                            "data": data.result,
                            "callback": function() {
                                if (sessionStorage.getItem('backId') == 1) { //查看编辑页面返回，回显原先的查询页码和每页数据条
                                    var pageNo3 = sessionStorage.getItem('pageNo2'),
                                        pageSize3 = sessionStorage.getItem('pageSize2'),
                                        prevFrom = JSON.parse(sessionStorage.getItem('prevFrom'));
                                    //显示原先的查询条件
                                    for (var i in prevFrom) {
                                        if(i == "cry"){
                                            $('#cry option').each(function(){
                                                if($(this).val() == prevFrom[i]){
                                                    $(this).attr('selected','selected')
                                                    $("#h-cry").val($(this).attr("data-number")) //乡code值回显
                                                }
                                            })
                                            cryVal = prevFrom[i]  //乡赋值，用于分页点击之后回显
                                        }
                                        else if (i == 'name') {
                                            /*$('#' + i).find('option:selected').text(prevFrom[i])*/
                                            $('#name option').each(function(){
                                                if($(this).val() == prevFrom[i]){
                                                    $(this).attr('selected','selected')
                                                    $("#h-name").val($(this).attr("data-number")) //村code值回显
                                                }
                                            })
                                            nameVal = prevFrom[i] //村赋值，用于分页点击之后回显
                                        } else {
                                            $('#' + i).val(prevFrom[i])
                                        }
                                    }
                                    //分页方法
                                    PagingMethods(pageNo3, pageSize3, data, getList);

                                } else {
                                    //分页方法
                                    PagingMethods(pageNo, pageSize, data, getList);
                                }
                                //删除从查看、编辑页面返回的标记,不然刷新会有问题
                                sessionStorage.removeItem("backId");

                                //点击数据项添加背景色
                                tdAddBg('tbody')
                                //乡回显
                                $('#cry').change(function(event) {
                                    /* Act on the event */
                                    cryVal = $(this).find('option:selected').val() //获取乡选择，用于查询条件回显，若不获取，条件会被重置
                                })
                                //村回显
                                $('#name').change(function(event) {
                                    /* Act on the event */
                                    nameVal = $(this).find('option:selected').val() //获取村选择，用于查询条件回显，若不获取，条件会被重置
                                })

                            }
                        });
                    }
                })
            });
        };
    //时间插件初始化
    laydate.render({
        elem: '#year', //指定元素
        type: 'year'
    })
    //乡和村下拉选择
    cryAndNameChange()

    // 流程
    ThisYear(); //当前年
    main.on('click', '.detail_btn', function() { //查看
        var id = $(this).parents('td').attr('id');
        areaId = $(this).parents('td').attr("areaId"); //地区ID
        mccms.goTo("povertyVillageMesInquire", "povertyVillageMesInquireEdit", { "id": id, "operated": 1, "areaId": areaId}); 
    });
    main.on('click', '.queryBtn', function() { //查询
        getList(pageNo, pageSize, 'true')
    });
    main.on('click', ".export_btn", function() { //导出功能
        location.href = "dequCon/exportqueryDequeue?" + $("#searchForm").serialize();
    });
    //进入编辑、查看页面前，保留查询条件
    main.on('click', '.save_from', function() {
        var pageNo2 = $('#pageCount').val(),
            pageSize2 = $('#pageSize').val()
        prevFrom = {
            "year": $('#year').val(),
            "cry": $('#cry').val(),
            "name": $('#name').val(),
            "nature": $('#nature').val(),
            "changes": $('#changes').val()
        };
        sessionStorage.setItem('pageNo2', pageNo2)
        sessionStorage.setItem('pageSize2', pageSize2)
        sessionStorage.setItem('from', $("#searchForm").serialize() + "&pageNo=" + pageNo2 + "&pageSize=" + pageSize2)
        sessionStorage.setItem('prevFrom', JSON.stringify(prevFrom))

    })
    getList(pageNo, pageSize);

}
/**
 * @submenu [贫困村变更-查看]
 * @Method povertyVillageMesInquireEdit
 * @date 2018-01-15
 * @author Arthur - caiwen
 */
/*--贫困村变更-查看--*/
function povertyVillageMesInquireEdit() {
    var id = mccms.getHash('id'), //用户id
        operated = mccms.getHash('operated') ? parseInt(mccms.getHash('operated')) : 0, //1为查看不可编辑,0为可编辑
        areaId = mccms.getHash('areaId'), //地区ID
        form = $('#editForm'),
        pageNo = 1, //当前第1页
        pageSize = 10, //每页10行
        pageCount = null, //总页数

        setNoticeToForm = function() { //获取用户数据
            mccms.ajax({
                "url": "/poorVi/getPoorVillageHistory?id=" + id,
                "cache": false,
                "method": "POST",
                success: function(data) {
                    var data = data || {
                        result: {}
                    };
                    data.result.detail = operated,
                        setForm(data.result);
                }
            })
        },
        setAddToForm = function() {
            setForm()
        },
        setForm = function(data) { //填充表单
            var cryId;
            var data = data || {};
            mccms.getHbs({
                "local": true,
                "hbsName": "editList",
                "container": form,
                "data": data,
                "callback": function() {
                    if (id) {
                        getList = function(pageNo, pageSize) {
                            mccms.ajax({
                                "url": "/helpTeam/getHelpTeamPersonByCondition",
                                "cache": false,
                                "method": "POST",
                                "data": {
                                    "pageNo": pageNo,
                                    "pageSize": pageSize,
                                    "team.village.id": areaId
                                },
                                "success": function(data) {
                                    mccms.getHbs({
                                        "local": true,
                                        "hbsName": "List1",
                                        "container": $("#tbody1"),
                                        "data": data.result,
                                        "callback": function() {
                                            //分页方法
                                            PagingMethods(pageNo, pageSize, data, getList)
                                            //分页样式
                                            $("#pageContainer select").css({
                                                'width': '100%',
                                                'height': 'auto'
                                            })
                                        }
                                    })

                                }
                            })

                        }
                        getList(pageNo, pageSize)
                    }


                    scrollToBox('nav_item')

                    var countryVal, //定义乡
                        natrueVal, //定义村
                        nature, //定义村属性
                        developmentVal, //定义发展方向
                        terrainVal, //定义地形地貌
                        asphaltVal, //定义沥青（水泥）路
                        busVal; //定义客运班车

                    if (s_cry || s_name) {
                        countryVal = s_cry;
                        natrueVal = s_name;
                    }
                    if (data.cry) {
                        countryVal = data.cry; //获取到乡的值 
                    }
                    if (data.name) {
                        natrueVal = data.name; //获取到自然村的值  
                    }
                    if (data.nature) {
                        nature = data.nature; //获取村属性值 
                    }
                    if (data.development) {
                        developmentVal = data.development; //获取发展方向的值
                    }
                    if (data.terrain) {
                        terrainVal = data.terrain; //获取地形地貌的值
                    }
                    if (data.asphalt) {
                        asphaltVal = data.asphalt; //获取沥青（水泥）路的值
                    }
                    if (data.bus) {
                        busVal = data.bus; //获取客运班车的值
                    }


                    //根据获取的值，将自然村属性selected选中
                    $("#nature-ads option").each(function(i) {
                        if ($(this).val() == name) {
                            $(this).attr("selected", "selected");
                        }
                    });
                    //根据获取的值，将自然村属性selected选中
                    $("#nature option").each(function(i) {
                        if ($(this).val() == nature) {
                            $(this).attr("selected", "selected");
                        }
                    });
                    //根据获取的值，将自然村属性selected选中
                    $("#development option").each(function(i) {
                        if ($(this).val() == developmentVal) {
                            $(this).attr("selected", "selected");
                        }
                    });
                    //根据获取的值，将自然村属性selected选中
                    $("#terrain option").each(function(i) {
                        if ($(this).val() == terrainVal) {
                            $(this).attr("selected", "selected");
                        }
                    });
                    //根据获取的值，将自然村属性selected选中
                    $("#asphalt option").each(function(i) {
                        if ($(this).val() == asphaltVal) {
                            $(this).attr("selected", "selected");
                        }
                    });
                    //根据获取的值，将自然村属性selected选中
                    $("#bus option").each(function(i) {
                        if ($(this).val() == busVal) {
                            $(this).attr("selected", "selected");
                        }
                    });

                    //10-11 wage add
                    mccms.ajax({
                        "url": "/area/findarea",
                        "cache": false,
                        "method": "POST",
                        "data": {
                            "fatherId": 3
                        },
                        success: function(data) {
                            var cryHtml = '<option value="" selected>请选择</option>';
                            for (var i = 0; i < data.result.length; i++) {
                                cryHtml += '<option data-number="' + data.result[i].areaCode + '" id="' + data.result[i].id + '" value="' + data.result[i].area + '">' + data.result[i].area + '</option>';
                            }
                            $("#cry-add").html(cryHtml);
                            //编辑和查看下地区select框的填充
                            if (countryVal) { //乡的值填充
                                $("#cry-add option").each(function(i) {
                                    if ($(this).val() == countryVal) {
                                        $(this).attr("selected", "selected");
                                        $("#s-cry-add").val($(this).val());
                                        if (s_Level == 4 || s_Level == 5) {
                                            $("#cry-add").attr("disabled", "disabled");
                                        }
                                        cryId = $(this).attr("id");
                                        mccms.ajax({
                                            "url": "/area/findarea",
                                            "cache": false,
                                            "method": "POST",
                                            "data": {
                                                "fatherId": cryId
                                            },
                                            success: function(data) {
                                                var naturalsHtml = '<option value="" selected>请选择</option>';
                                                for (var i = 0; i < data.result.length; i++) {
                                                    naturalsHtml += '<option data-number="' + data.result[i].areaCode + '" id="' + data.result[i].id + '" value="' + data.result[i].area + '">' + data.result[i].area + '</option>';
                                                }
                                                $("#naturals-add").html(naturalsHtml);
                                                if (natrueVal) { //村的值填充
                                                    $("#naturals-add option").each(function(i) {
                                                        if ($(this).val() == natrueVal) {
                                                            $(this).attr("selected", "selected");
                                                            if (s_Level == 4 || s_Level == 5) {
                                                                $("#cry-add").attr("disabled", "disabled");
                                                            }
                                                            cryId = $(this).attr("id");
                                                            $(this).attr("selected", "selected");
                                                            $("#s-naturals-add").val($(this).val());
                                                            if (s_Level == 5) {
                                                                $("#naturals-add").attr("disabled", "disabled");
                                                            }
                                                            var natrueNum = $(this).attr("data-number"); //选中村之后，自动填充村编号
                                                            var natureId = $(this).attr("id");
                                                            $("#natureId").val(natureId);
                                                            $("#code").val(natrueNum);
                                                        }
                                                    });
                                                }
                                            }
                                        });
                                    }
                                });
                            }
                        }
                    })
                }
            })

        },
        subMsg = function(ele) { //提交用户数据
            var data = form.serialize(),
                valid = form.valid(),
                url = id ? "/poorVi/updatePoorVillage" : "/poorVi/addPoorVillage"; //前者编辑API，后者新增API
            valid &&
                mccms.ajax({
                    "url": url,
                    "data": data,
                    "lock": true,
                    "method": "POST",
                    "beforeSend": function() {
                        ele && ele.attr('disabled', 'disabled');
                    },
                    "complete": function() {
                        ele && ele.removeAttr('disabled');
                    },
                    "success": function(data) {
                        if (data.message == '该地区是贫困村') {
                            layer.msg('该地区已是贫困村,请重新选择村！')
                        } else {
                            layer.msg(data.message)
                            id ? mccms.gobackFromEdit() : mccms.goBack()
                        }



                    }
                })
        };

    // 流程
    id ? setNoticeToForm() : setAddToForm(),
        form.on('click', '.sub_btn', function() {
            myRequired("editForm", "popup");
            subMsg($(this));
        })

}











/**
 * @submenu [贫困户变更查询]
 * @Method povertyStrickenMesInquire
 * @date 2017-11-15
 * @author Arthur - caiwen
 * @parameter main 主页面容器
 * @parameter mainList 主页面hbs模板
 * @parameter $("#searchForm").serialize() 查询时表单序列化参数
 */
/*--贫困户变更查询--*/
function povertyStrickenMesInquire() {
    // 变量声明
    var main = $('#mainCon'),
        cryVal = s_cry, //乡的选中
        nameVal = s_name, //村的选中
        pageNo = 1, //当前第1页
        pageSize = 10, //每页10行
        pageCount = null,
        backFrom, //进入编辑、查看页面时，主页面的查询条件
        getList = function(pageNo, pageSize, checkType) { //getList() 主页面渲染
            areaSelected(cryVal, nameVal, checkType, function() { //areaSelected() 权限控制方法
                
                if (sessionStorage.getItem('backId') == 1) { //从编辑、查看页面返回时，根据原先的查询条件查询
                    backFrom = sessionStorage.getItem('from')
                } else { //刷新时，重置查询条件
                    backFrom = $("#searchForm").serialize() + "&pageNo=" + pageNo + "&pageSize=" + pageSize
                }
                mccms.ajax({ //贫困户变更查询API
                    "url": "/ridPo/queryRidPoor",
                    "cache": false,
                    "method": "POST",
                    "data": backFrom,
                    "success": function(data) {
                        var data = data;
                        mccms.getHbs({
                            "local": true,
                            "hbsName": "mainList",
                            "container": $("#tbody"),
                            "data": data.result,
                            "callback": function() {
                                if (sessionStorage.getItem('backId') == 1) { //查看编辑页面返回，回显原先的查询页码和每页数据条
                                    var pageNo3 = sessionStorage.getItem('pageNo2'),
                                        pageSize3 = sessionStorage.getItem('pageSize2'),
                                        prevFrom = JSON.parse(sessionStorage.getItem('prevFrom'));
                                    //显示原先的查询条件
                                    for (var i in prevFrom) {
                                        if(i == "cry"){
                                            $('#cry option').each(function(){
                                                if($(this).val() == prevFrom[i]){
                                                    $(this).attr('selected','selected')
                                                    $("#h-cry").val($(this).attr("data-number")) //乡code值回显
                                                }
                                            })
                                            cryVal = prevFrom[i]  //乡赋值，用于分页点击之后回显
                                        }
                                        else if (i == 'name') {
                                            /*$('#' + i).find('option:selected').text(prevFrom[i])*/
                                            $('#name option').each(function(){
                                                if($(this).val() == prevFrom[i]){
                                                    $(this).attr('selected','selected')
                                                    $("#h-name").val($(this).attr("data-number")) //村code值回显
                                                }
                                            })
                                            nameVal = prevFrom[i]
                                        } else {
                                            $('#' + i).val(prevFrom[i])
                                        }
                                    }
                                    //分页方法
                                    PagingMethods(pageNo3, pageSize3, data, getList);

                                } else {
                                    //分页方法
                                    PagingMethods(pageNo, pageSize, data, getList);
                                }
                                //删除从查看、编辑页面返回的标记,不然刷新会有问题
                                sessionStorage.removeItem("backId");
                                
                                //点击数据项添加背景色
                                tdAddBg('tbody')
                                //乡回显
                                $('#cry').change(function(event) {
                                    /* Act on the event */
                                    cryVal = $(this).find('option:selected').val() //获取乡选择，用于查询条件回显，若不获取，条件会被重置
                                })
                                //村回显
                                $('#name').change(function(event) {
                                    /* Act on the event */
                                    nameVal = $(this).find('option:selected').val() //获取村选择，用于查询条件回显，若不获取，条件会被重置
                                })

                            }
                        });
                    }
                })
            });
        };
    //时间插件初始化
    laydate.render({ //年度
        elem: '#year',
        type: 'year'
    })
    laydate.render({ //变更开始时间
        elem: '#year2',
        type: 'datetime'
    })
    laydate.render({ //变更结束时间
        elem: '#year3',
        type: 'datetime'
    })
    laydate.render({ //经办开始时间
        elem: '#year4',
        type: 'datetime'
    })
    laydate.render({ //经办结束时间
        elem: '#year5',
        type: 'datetime'
    })
    //乡和村下拉选择
    cryAndNameChange()

    // 流程
    ThisYear(); //当前年
    main.on('click', '.detail_btn', function() { //查看
        var id = $(this).parents('td').attr('id');
        mccms.goTo("povertyStrickenMesInquire", "povertyStrickenMesInquireEdit", { "id": id, "operatedState": 1, "detail": 1 });
    });
    main.on('click', '.queryBtn', function() { //查询
        getList(pageNo, pageSize, 'true')
    });
    main.on('click', ".export_btn", function() { //导出功能
        location.href = "ridPo/exportqueryRidPoor?" + $("#searchForm").serialize();
    });
    //进入编辑、查看页面前，保留查询条件
    main.on('click', '.save_from', function() {
        var pageNo2 = $('#pageCount').val(),
            pageSize2 = $('#pageSize').val()
        prevFrom = {
            "year": $('#year').val(),
            "cry": $('#cry').val(),
            "name": $('#name').val(),
            "poorName": $('#poorName').val(),
            "idNumber": $('#idNumber').val(),
            "changes": $('#changes').val()
        };
        sessionStorage.setItem('pageNo2', pageNo2)
        sessionStorage.setItem('pageSize2', pageSize2)
        sessionStorage.setItem('from', $("#searchForm").serialize() + "&pageNo=" + pageNo2 + "&pageSize=" + pageSize2)
        sessionStorage.setItem('prevFrom', JSON.stringify(prevFrom))

    })
    getList(pageNo, pageSize);

}

/**
 * @submenu [贫困户变更查询-查看]
 * @Method povertyStrickenMesInquireEdit
 * @date 2017-11-16
 * @author Arthur - caiwen
 * 
 */
/*--贫困户变更查询--*/

function povertyStrickenMesInquireEdit() {
    // 变量声明
    var id = mccms.getHash('id'), //用户id
        operatedState = parseInt(mccms.getHash('operatedState')),
        detail = mccms.getHash('detail'),
        isEdit = mccms.getHash('isEdit'), //编辑状态
        addTime = sessionStorage.addTime; //使用H5本地储存获取时间

    var main = $('#MainList'),
        addMain = $('#addPopup'),
        modelForm = $('#modelForm'),
        memberArr = [],
        operated = 0,
        village1Id = null,
        size = 10,
        no = 1,
        pageCount = null,
        cryVal = s_cry, //乡的选中
        nameVal = s_name, //村的选中
        urlStr = "&cry=" + s_cry + "&name=" + s_name,
        // id ：操作记录的id
        // operated 0为返贫，1为脱贫
        getDetail = function(id) { //新增、查看、编辑方法 刷新页面
            if (!id) { //新增-页面
                //渲染主页面,但没填充数据
                mccms.getHbs({
                    "local": true,
                    "hbsName": "info",
                    "container": $("#addPopup"),
                    "data": {
                        operated: 1
                    },
                    "callback": function() {
                        modelForm = $('#modelForm')
                        modelForm.mcFormValide(); //绑定表单验证
                        getW()
                        //nav条定位锚点
                        scrollToBox("nav-item")
                        // //清空家庭成员列表
                        // mccms.ajax({ //新增时清空家庭成员列表API
                        //     "url": "/poorFa/deleteFamilyFid",
                        //     "cache": false,
                        //     "method": "POST"
                        // })
                        //家庭成员重置按钮
                        $("#modelForm .reset-btn").on("click", function() {
                            mccms.getHbs({ //家庭成员模板
                                "local": true,
                                "hbsName": "memberForm",
                                "container": $("#modelForm1"),
                                "data": {},
                                "callback": function() {
                                    laydate.render({ //出生日期
                                        elem: '#birthTime',
                                        max: nowDay()
                                    });
                                    laydate.render({ //入学时间
                                        elem: '#enterTime'
                                    });
                                }
                            })
                        })

                        //家庭成员新增按钮
                        $("#modelForm #addMember-btn").on("click", function() {
                            var checkboxMember = $('.checkbox-member input:checked')
                            if (checkboxMember.length) {
                                layer.msg('新增时不能勾选家庭成员')
                                return false
                            }
                            $("#addFamilyMask").show();
                            $('#mainContainer').addClass('noScroll');

                            mccms.getHbs({ //家庭成员弹窗
                                "local": true,
                                "hbsName": "memberForm",
                                "container": $("#modelForm1"),
                                "data": {},
                                "callback": function() {
                                    laydate.render({ //出生日期
                                        elem: '#birthTime',
                                        max: nowDay()
                                    });
                                    laydate.render({ //入学时间
                                        elem: '#enterTime'
                                    });
                                    //身份证读取
                                    function ClearIDCard() {
                                        CVR_IDCard.Name = "";
                                        CVR_IDCard.NameL = "";
                                        CVR_IDCard.Sex = "";
                                        CVR_IDCard.SexL = "";
                                        CVR_IDCard.Nation = "";
                                        //CVR_IDCard.NationL="";
                                        CVR_IDCard.Born = "";
                                        //CVR_IDCard.BornL="";
                                        CVR_IDCard.Address = "";
                                        CVR_IDCard.CardNo = "";
                                        CVR_IDCard.Police = "";
                                        CVR_IDCard.Activity = "";
                                        CVR_IDCard.NewAddr = "";

                                        return true;
                                    }

                                    function ReadIDCard() {
                                        CVR_IDCard.PhotoPath = 'C:\\'
                                        CVR_IDCard.TimeOut = 3;
                                        ClearIDCard();
                                        // return true;
                                    }
                                    $("#readyCard-btn").unbind("click");
                                    $('#readyCard-btn').on('click', function() {
                                        ReadIDCard()
                                        var State = CVR_IDCard.GetState;
                                        var strReadResult = CVR_IDCard.ReadCard;
                                        if (State !== '0') {
                                            layer.msg('请插入设备')
                                            return false
                                        }
                                        if (strReadResult !== '0') {
                                            layer.msg('请检查是否正常放置了身份证！')
                                            return false
                                        }
                                        if (CVR_IDCard.Sex === '1') {
                                            $('#sex').val('男')
                                        } else {
                                            $('#sex').val('女')
                                        }
                                        $('#name1').val(CVR_IDCard.NameL)
                                        $('#idNumber').val(CVR_IDCard.CardNo)
                                        $('#birthTime').val(CVR_IDCard.BornL)

                                        layer.msg('身份信息采集成功！', {
                                            icon: 1,
                                            shade: [0.8, '#000']
                                        })
                                    })

                                }
                            });
                        })

                        //家庭成员删除按钮
                        $('#deleteMember-btn').on('click', function() {
                            var checkboxMember = $('.checkbox-member input:checked')
                            if (!checkboxMember.length) {
                                layer.msg('请勾选家庭成员')
                                return false
                            }
                            var checkArr = []
                            checkboxMember.each(function(i, item) {
                                checkArr.push($(item).attr('id'))
                            })
                            mccms.ajax({ //删除家庭成员API
                                "url": "/poorFa/deleteFamilyid",
                                "cache": false,
                                "method": "POST",
                                "data": {
                                    sid: checkArr.join(',')
                                },
                                "success": function(data) {
                                    layer.msg('删除成功')
                                    //刷新
                                    getMemberList();
                                }
                            })
                        })

                        //家庭成员编辑按钮
                        $('#modelForm #editMember-btn').on('click', function() {
                            $("#addFamilyMask #div1").text("编辑家庭成员")
                            var checkboxMember = $('.checkbox-member input:checked') //被勾选家庭成员
                            var familyMemberId = checkboxMember.attr("id"); //被勾选家庭成员id
                            if (!checkboxMember.length) {
                                layer.msg('请勾选家庭成员')
                                return false
                            }
                            if (checkboxMember.length > 1) {
                                layer.msg('只能单个修改')
                                return false
                            }
                            var checkArr = []
                            checkboxMember.each(function(i, item) {
                                checkArr.push($(item).attr('id'))
                            })

                            $("#addFamilyMask").show(); //家庭成员的弹窗
                            $('#mainContainer').addClass('noScroll');

                            //请求单个家庭成员数据
                            mccms.ajax({ //查询单个家庭成员API
                                "url": "/poorFa/findFamily",
                                "cache": false,
                                "method": "POST",
                                "data": {
                                    "sid": familyMemberId
                                },
                                success: function(data) {
                                    mccms.getHbs({ //家庭成员弹窗
                                        "local": true,
                                        "hbsName": "memberForm",
                                        "container": $("#modelForm1"),
                                        "data": data.result[0],
                                        "callback": function() {
                                            laydate.render({ //出生日期
                                                elem: '#birthTime',
                                                max: nowDay()
                                            });
                                            laydate.render({ //入学时间
                                                elem: '#enterTime'
                                            });

                                            //身份证读取
                                            function ClearIDCard() {
                                                CVR_IDCard.Name = "";
                                                CVR_IDCard.NameL = "";
                                                CVR_IDCard.Sex = "";
                                                CVR_IDCard.SexL = "";
                                                CVR_IDCard.Nation = "";
                                                //CVR_IDCard.NationL="";
                                                CVR_IDCard.Born = "";
                                                //CVR_IDCard.BornL="";
                                                CVR_IDCard.Address = "";
                                                CVR_IDCard.CardNo = "";
                                                CVR_IDCard.Police = "";
                                                CVR_IDCard.Activity = "";
                                                CVR_IDCard.NewAddr = "";

                                                return true;
                                            }

                                            function ReadIDCard() {
                                                CVR_IDCard.PhotoPath = 'C:\\'
                                                CVR_IDCard.TimeOut = 3;
                                                ClearIDCard();
                                                // return true;
                                            }
                                            $("#readyCard-btn").unbind("click");
                                            $('#readyCard-btn').on('click', function() {
                                                ReadIDCard()
                                                var State = CVR_IDCard.GetState;
                                                var strReadResult = CVR_IDCard.ReadCard;
                                                if (State !== '0') {
                                                    layer.msg('请插入设备')
                                                    return false
                                                }
                                                if (strReadResult !== '0') {
                                                    layer.msg('请检查是否正常放置了身份证！')
                                                    return false
                                                }
                                                if (CVR_IDCard.Sex === '1') {
                                                    $('#sex').val('男')
                                                } else {
                                                    $('#sex').val('女')
                                                }
                                                $('#name1').val(CVR_IDCard.NameL)
                                                $('#idNumber').val(CVR_IDCard.CardNo)
                                                $('#birthTime').val(CVR_IDCard.BornL)

                                                layer.msg('身份信息采集成功！', {
                                                    icon: 1,
                                                    shade: [0.8, '#000']
                                                })
                                            })
                                        }
                                    })
                                }
                            })
                        })

                        //关闭弹窗
                        $('.close-btn').on('click', function() {
                            $("#addFamilyMask").hide();
                            $('#mainContainer').removeClass('noScroll')
                        })

                        /*-- 帮扶责任人模块 start --*/

                        //帮扶责任人新增按钮
                        $("#addPersons-btn").on("click", function() {
                            if ($("input[name='name']")) { //村级别时直接获取村的id
                                village1Id = $("#village1").find("option:selected").attr("id");
                            }
                            if (!village1Id) {
                                layer.msg("请选择行政村！");
                                return false;
                            }

                            layer.open({
                                type: 1,
                                title: "帮扶责任人结对信息",
                                area: ['80%', '60%'], //宽高
                                content: $("#div5"),
                                success: function() {
                                    mccms.ajax({ //村 查找对应 帮扶责任人结对信息API
                                        "url": "/helppeson/getHelpPersonByAreaId",
                                        "cache": false,
                                        "method": "POST",
                                        "data": {
                                            areaId: village1Id, //村的id
                                            pageSize: 10,
                                            pageNo: 1
                                        },
                                        "success": function(data) {
                                            if (data.result) {
                                                mccms.getHbs({
                                                    "local": true,
                                                    "hbsName": "addHelpList",
                                                    "container": $("#addHelpTobdy"),
                                                    "data": data,
                                                    "callback": function() {
                                                        mccms.pageHtml(data, getHelpPersonList, ''); //分页
                                                        //标记已选择的责任人
                                                        var personChecked = $("#helpTobdy input[name=help]"); //主页面-已选择责任人
                                                        var addPersonAll = $("#addHelpTobdy input[name=addHelp]"); //弹窗页面-所有责任人
                                                        personChecked.each(function(item) {
                                                            item = $(this).attr("id");
                                                            $('#addHelpTobdy input[id=' + item + ']').attr("checked", "checked")
                                                        })

                                                    }
                                                });
                                            } else {
                                                mccms.getHbs({
                                                    "local": true,
                                                    "hbsName": "addHelpList",
                                                    "container": $("#addHelpTobdy"),
                                                    "data": '',
                                                    "callback": function() {}
                                                });
                                            }
                                        }
                                    })




                                }


                            })
                        })
                        //帮扶责任人保存按钮
                        $("#keepPersons-btn").on("click", function() {

                            //帮扶责任人多选
                            var helpArr = $('#addHelpTobdy input[name=addHelp]:checked')
                            var arr1 = []; //帮扶责任人id数组
                            if (helpArr.length == 0) {
                                layer.msg("请先勾选帮扶责任人！")
                                return false
                            }
                            if (helpArr.length) {
                                helpArr.each(function(i, item) {
                                    arr1.push($(item).attr('id'))
                                })
                            }
                            layer.closeAll(); //关闭弹窗
                            var sid = arr1 ? arr1.join(',') : ''
                            getHelpPersonList(sid);

                        })
                        //帮扶责任人删除按钮
                        $("#deletePersons-btn").on("click", function() {
                            //帮扶责任人多选
                            var allHelpArr = $('#helpTobdy input[name=help]'); //所有责任人
                            var helpArr = allHelpArr.not(":checked"); //非选定状态责任人
                            var helpArred = $('#helpTobdy input[name=help]:checked'); //选定状态责任人
                            if (helpArred.length == 0) {
                                layer.msg("请先勾选帮扶责任人！")
                                return false
                            }
                            if (allHelpArr.length == 1 || allHelpArr.length == helpArred.length && helpArred) { //剩余一个责任人 或 删除全部时,清空表格
                                mccms.getHbs({
                                    "local": true,
                                    "hbsName": "helpList",
                                    "container": $("#helpTobdy"),
                                    "data": '',
                                    "callback": function() {
                                        layer.msg("删除成功！")
                                    }
                                });

                            } else { //剩余多个责任人时
                                var arr1 = []; //责任人id数组
                                if (helpArr.length) {
                                    helpArr.each(function(i, item) {
                                        arr1.push($(item).attr('id'))
                                    })
                                }

                                var sid = arr1 ? arr1.join(',') : ''
                                getHelpPersonList(sid, true);
                            }
                        })
                        //帮扶责任人取消按钮
                        $("#cancelPersons-btn").on("click", function() {
                            layer.closeAll(); //关闭弹窗
                        })

                        /*-- 帮扶责任人模块 end -- */

                    }
                })
                //新增时隐藏 帮扶日志按钮
                $("#helpLog-btn").remove();

                return false;
            }

            //查看与编辑页面
            mccms.ajax({ //贫困户变更详情API - 参数: 贫困户id 
                "url": "/poorFa/getPoorFamilyHistory",
                "cache": false,
                "method": "POST",
                "data": {
                    "id": id
                },
                "success": function(data) {
                    // 改造填充数据
                    data.result.poorFamily.operated = operated
                    data.result.poorFamily.detail = detail
                    data.result.poorFamily.operatedState = operatedState; //operatedState==1为查看不可编辑,0为可编辑
                    data.result.poorFamily.edit = 1;

                    mccms.getHbs({ //填充表单
                        "local": true,
                        "hbsName": "info", //主模板
                        "container": $("#addPopup"), //主页面
                        "data": data.result,
                        "callback": function() {
                            //点位锚点
                            scrollToBox("nav-item")

                            //查看状态时,删除掉家庭成员的"新增、删除、编辑"三个按钮
                            if (data.result.poorFamily.operatedState == 1) {
                                $(".poverty-btnGroup").remove();
                                $("nav .c-primary").html("查看贫困户");
                            }
                            
                            //填充省市区乡村值
                            getW({
                                province: data.result.poorFamily.province,
                                city: data.result.poorFamily.city,
                                county: data.result.poorFamily.county,
                                country: data.result.poorFamily.country,
                                village: data.result.poorFamily.village
                            })

                            //填充其他致贫原因
                            var otherArr = data.result.poorFamily.other ? data.result.poorFamily.other.split(',') : ''
                            if (otherArr) {
                                for (var i = 0; i < otherArr.length; i++) {
                                    $('#other input').each(function(j, item) {
                                        if (item.value === otherArr[i]) {
                                            $(item).prop('checked', true)
                                        }
                                    })
                                }
                            }

                            modelForm = $('#modelForm'); //主模板表单
                            modelForm.mcFormValide(); //绑定表单验证

                            //填充家庭成员列表
                            mccms.getHbs({
                                "local": true,
                                "hbsName": "list",
                                "container": $("#tbody"),
                                "data": {
                                    result: data.result.poorFamily.family
                                }
                            });

                            //新增、删除、编辑按钮组
                            if (isEdit) { //isEdit==1表示编辑页面
                                //家庭成员重置按钮
                                $("#modelForm .reset-btn").on("click", function() {
                                    mccms.getHbs({ //家庭成员模板
                                        "local": true,
                                        "hbsName": "memberForm",
                                        "container": $("#modelForm1"),
                                        "data": {}
                                    })
                                })

                                //家庭成员新增按钮
                                $("#modelForm #addMember-btn").on("click", function() {
                                    var checkboxMember = $('.checkbox-member input:checked')
                                    if (checkboxMember.length) {
                                        layer.msg('新增时不能勾选家庭成员')
                                        return false
                                    }
                                    $("#addFamilyMask").show();
                                    $('#mainContainer').addClass('noScroll');

                                    mccms.getHbs({ //家庭成员弹窗
                                        "local": true,
                                        "hbsName": "memberForm",
                                        "container": $("#modelForm1"),
                                        "data": {},
                                        "callback": function() {
                                            laydate.render({ //出生日期
                                                elem: '#birthTime',
                                                max: nowDay()
                                            });
                                            laydate.render({ //入学时间
                                                elem: '#enterTime'
                                            });

                                            //身份证读取
                                            function ClearIDCard() {
                                                CVR_IDCard.Name = "";
                                                CVR_IDCard.NameL = "";
                                                CVR_IDCard.Sex = "";
                                                CVR_IDCard.SexL = "";
                                                CVR_IDCard.Nation = "";
                                                //CVR_IDCard.NationL="";
                                                CVR_IDCard.Born = "";
                                                //CVR_IDCard.BornL="";
                                                CVR_IDCard.Address = "";
                                                CVR_IDCard.CardNo = "";
                                                CVR_IDCard.Police = "";
                                                CVR_IDCard.Activity = "";
                                                CVR_IDCard.NewAddr = "";

                                                return true;
                                            }

                                            function ReadIDCard() {
                                                CVR_IDCard.PhotoPath = 'C:\\'
                                                CVR_IDCard.TimeOut = 3;
                                                ClearIDCard();
                                                // return true;
                                            }
                                            $("#readyCard-btn").unbind("click");
                                            $('#readyCard-btn').on('click', function() {
                                                ReadIDCard()
                                                var State = CVR_IDCard.GetState;
                                                var strReadResult = CVR_IDCard.ReadCard;
                                                if (State !== '0') {
                                                    layer.msg('请插入设备')
                                                    return false
                                                }
                                                if (strReadResult !== '0') {
                                                    layer.msg('请检查是否正常放置了身份证！')
                                                    return false
                                                }
                                                if (CVR_IDCard.Sex === '1') {
                                                    $('#sex').val('男')
                                                } else {
                                                    $('#sex').val('女')
                                                }
                                                $('#name1').val(CVR_IDCard.NameL)
                                                $('#idNumber').val(CVR_IDCard.CardNo)
                                                $('#birthTime').val(CVR_IDCard.BornL)

                                                layer.msg('身份信息采集成功！', {
                                                    icon: 1,
                                                    shade: [0.8, '#000']
                                                })
                                            })
                                        }
                                    });
                                })

                                //家庭成员删除按钮
                                $('#deleteMember-btn').on('click', function() {
                                    var checkboxMember = $('.checkbox-member input:checked')
                                    if (!checkboxMember.length) {
                                        layer.msg('请勾选家庭成员')
                                        return false
                                    }
                                    var checkArr = []
                                    checkboxMember.each(function(i, item) {
                                        checkArr.push($(item).attr('id'))
                                    })
                                    mccms.ajax({ //删除家庭成员API
                                        "url": "/poorFa/deleteFamilyid",
                                        "cache": false,
                                        "method": "POST",
                                        "data": {
                                            sid: checkArr.join(',')
                                        },
                                        "success": function(data) {
                                            layer.msg('删除成功')
                                            getDetail(id); //刷新
                                        }
                                    })
                                })

                                //家庭成员编辑按钮
                                $('#modelForm #editMember-btn').on('click', function() {
                                    $("#addFamilyMask #div1").text("编辑家庭成员")
                                    var checkboxMember = $('.checkbox-member input:checked') //被勾选家庭成员
                                    var familyMemberId = checkboxMember.attr("id"); //被勾选家庭成员id
                                    if (!checkboxMember.length) {
                                        layer.msg('请勾选家庭成员')
                                        return false
                                    }
                                    if (checkboxMember.length > 1) {
                                        layer.msg('只能单个修改')
                                        return false
                                    }
                                    var checkArr = []
                                    checkboxMember.each(function(i, item) {
                                        checkArr.push($(item).attr('id'))
                                    })

                                    $("#addFamilyMask").show(); //家庭成员的弹窗
                                    $('#mainContainer').addClass('noScroll');

                                    //请求单个家庭成员数据
                                    mccms.ajax({ //查询单个家庭成员API
                                        "url": "/poorFa/findFamily",
                                        "cache": false,
                                        "method": "POST",
                                        "data": {
                                            "sid": familyMemberId
                                        },
                                        success: function(data) {
                                            mccms.getHbs({ //家庭成员弹窗
                                                "local": true,
                                                "hbsName": "memberForm",
                                                "container": $("#modelForm1"),
                                                "data": data.result[0],
                                                "callback": function() {
                                                    laydate.render({ //出生日期
                                                        elem: '#birthTime',
                                                        max: nowDay()
                                                    });
                                                    laydate.render({ //入学时间
                                                        elem: '#enterTime'
                                                    });

                                                    //身份证读取
                                                    function ClearIDCard() {
                                                        CVR_IDCard.Name = "";
                                                        CVR_IDCard.NameL = "";
                                                        CVR_IDCard.Sex = "";
                                                        CVR_IDCard.SexL = "";
                                                        CVR_IDCard.Nation = "";
                                                        //CVR_IDCard.NationL="";
                                                        CVR_IDCard.Born = "";
                                                        //CVR_IDCard.BornL="";
                                                        CVR_IDCard.Address = "";
                                                        CVR_IDCard.CardNo = "";
                                                        CVR_IDCard.Police = "";
                                                        CVR_IDCard.Activity = "";
                                                        CVR_IDCard.NewAddr = "";

                                                        return true;
                                                    }

                                                    function ReadIDCard() {
                                                        CVR_IDCard.PhotoPath = 'C:\\'
                                                        CVR_IDCard.TimeOut = 3;
                                                        ClearIDCard();
                                                        // return true;
                                                    }

                                                    function editData() {
                                                        if (CVR_IDCard.Sex === '1') {
                                                            $('#sex').val('男')
                                                        } else {
                                                            $('#sex').val('女')
                                                        }
                                                        $('#name1').val(CVR_IDCard.NameL)
                                                        $('#idNumber').val(CVR_IDCard.CardNo)
                                                        $('#birthTime').val(CVR_IDCard.BornL)
                                                    }
                                                    $("#readyCard-btn").unbind("click");
                                                    $('#readyCard-btn').on('click', function() {
                                                        ReadIDCard()
                                                        var State = CVR_IDCard.GetState;
                                                        var strReadResult = CVR_IDCard.ReadCard;
                                                        if (State !== '0') {
                                                            layer.msg('请插入设备')
                                                            return false
                                                        }
                                                        if (strReadResult !== '0') {
                                                            layer.msg('请检查是否正常放置了身份证！')
                                                            return false
                                                        }
                                                        mccms.ajax({
                                                            "url": "/poorFa/IDcard",
                                                            "cache": false,
                                                            "method": "POST",
                                                            "data": {
                                                                sid: checkArr.join(','),
                                                                name: CVR_IDCard.NameL,
                                                                idNumber: CVR_IDCard.CardNo,
                                                                birthTime: CVR_IDCard.BornL,
                                                                sex: CVR_IDCard.Sex === '1' ? '男' : '女'
                                                            },
                                                            "success": function(data) {
                                                                if (data.message === '身份信息核对一致！') {
                                                                    layer.msg(data.message, {
                                                                        icon: 1,
                                                                        area: ['400px', '70px'],
                                                                        shade: [0.8, '#000']
                                                                    })
                                                                } else {
                                                                    layer.msg(data.message, {
                                                                        icon: 2,
                                                                        area: ['400px', '70px'],
                                                                        shade: [0.8, '#000']
                                                                    })
                                                                }
                                                                editData()
                                                            }
                                                        })
                                                    })

                                                }
                                            })
                                        }
                                    })
                                })



















                                //关闭弹窗
                                $('.close-btn').on('click', function() {
                                    $("#addFamilyMask").hide();
                                    $('#mainContainer').removeClass('noScroll')
                                })

                                /*帮扶责任人模块 start*/
                                //帮扶责任人新增按钮
                                $("#addPersons-btn").on("click", function() {
                                    if ($("input[name='name']")) { //村级别时直接获取村的id
                                        village1Id = $("#village1").find("option:selected").attr("id");
                                    }
                                    if (!village1Id) {
                                        layer.msg("请先填写家庭住址！");
                                        return false;
                                    }
                                    layer.open({
                                        type: 1,
                                        title: "帮扶责任人结对信息",
                                        area: ['80%', '60%'], //宽高
                                        content: $("#div5"),
                                        success: function() {
                                            mccms.ajax({ //村 查找对应 帮扶责任人结对信息API
                                                "url": "/helppeson/getHelpPersonByAreaId",
                                                "cache": false,
                                                "method": "POST",
                                                "data": {
                                                    areaId: village1Id, //村的id
                                                    pageSize: 10,
                                                    pageNo: 1
                                                },
                                                "success": function(data) {
                                                    if (data.result) {
                                                        mccms.getHbs({
                                                            "local": true,
                                                            "hbsName": "addHelpList",
                                                            "container": $("#addHelpTobdy"),
                                                            "data": data,
                                                            "callback": function() {
                                                                mccms.pageHtml(data, getHelpPersonList, ''); //分页
                                                                //标记已选择的责任人
                                                                var personChecked = $("#helpTobdy input[name=help]"); //主页面-已选择责任人
                                                                var addPersonAll = $("#addHelpTobdy input[name=addHelp]"); //弹窗页面-所有责任人
                                                                personChecked.each(function(item) {
                                                                    item = $(this).attr("id");
                                                                    $('#addHelpTobdy input[id=' + item + ']').attr("checked", "checked")
                                                                })

                                                            }
                                                        });
                                                    } else {
                                                        mccms.getHbs({
                                                            "local": true,
                                                            "hbsName": "addHelpList",
                                                            "container": $("#addHelpTobdy"),
                                                            "data": '',
                                                            "callback": function() {}
                                                        });
                                                    }
                                                }
                                            })




                                        }
                                    })
                                })
                                //帮扶责任人保存按钮
                                $("#keepPersons-btn").on("click", function() {

                                    //帮扶责任人多选
                                    var helpArr = $('#addHelpTobdy input[name=addHelp]:checked')
                                    var arr1 = []; //帮扶责任人id数组
                                    if (helpArr.length == 0) {
                                        layer.msg("请先勾选帮扶责任人！")
                                        return false
                                    }
                                    if (helpArr.length) {
                                        helpArr.each(function(i, item) {
                                            arr1.push($(item).attr('id'))
                                        })
                                    }
                                    layer.closeAll(); //关闭弹窗
                                    var sid = arr1 ? arr1.join(',') : ''
                                    getHelpPersonList(sid);

                                })
                                //帮扶责任人删除按钮
                                $("#deletePersons-btn").on("click", function() {

                                    //帮扶责任人多选
                                    var allHelpArr = $('#helpTobdy input[name=help]'); //所有责任人
                                    var helpArr = allHelpArr.not(":checked"); //非选定状态责任人
                                    var helpArred = $('#helpTobdy input[name=help]:checked'); //选定状态责任人
                                    if (allHelpArr.length == 0) { return false }
                                    if (allHelpArr.length == 1 || allHelpArr.length == helpArred.length && helpArred) { //剩余一个责任人 或 删除全部时,清空表格
                                        mccms.getHbs({
                                            "local": true,
                                            "hbsName": "helpList",
                                            "container": $("#helpTobdy"),
                                            "data": '',
                                            "callback": function() {
                                                layer.msg("删除成功！")
                                            }
                                        });

                                    } else { //剩余多个责任人时
                                        var arr1 = []; //责任人id数组
                                        if (helpArr.length) {
                                            helpArr.each(function(i, item) {
                                                arr1.push($(item).attr('id'))
                                            })
                                        }

                                        var sid = arr1 ? arr1.join(',') : ''
                                        getHelpPersonList(sid, true);
                                    }

                                })

                                //帮扶责任人取消按钮
                                $("#cancelPersons-btn").on("click", function() {
                                    layer.closeAll(); //关闭弹窗
                                })

                                /*帮扶责任人模块 end*/



                            }
                            //帮扶责任人结对信息回显
                            if (detail && !operated) {
                                mccms.getHbs({
                                    "local": true,
                                    "hbsName": "helpList",
                                    "container": $("#helpTobdy"),
                                    "data": {
                                        result: data.result.poorFamily.helpPersons
                                    },
                                    "callback": function() {}
                                });
                            }


                        }
                    });
                }
            })


        },
        getMemberList = function(id) { //家庭成员列表
            var familyUrl = id ? "/poorFa/getPoorFamily" : "/poorFa/queryFamily"; //前者表示编辑页面时API，后者表示新增页面时API
            var familyData = id ? { "id": id } : ""; //前者表示编辑页面时参数-用户id，后者表示新增页面时 参数
            mccms.ajax({ //贫困户详情API - 参数: 贫困户id  
                "url": familyUrl,
                "cache": false,
                "method": "POST",
                "data": familyData,
                "success": function(data) {
                    var resultData; //填充的数据
                    if (id) { //编辑页面时
                        data.result.poorFamily.family.forEach(function(item) { //所有家庭成员的id,用于保存到对应贫困户里
                            memberArr.push(item.id)
                        })
                        resultData = { result: data.result.poorFamily.family };
                    } else { //新增页面时
                        data.result.forEach(function(item) {
                            memberArr.push(item.id)
                        })
                        resultData = { result: data.result };
                    }

                    mccms.getHbs({
                        "local": true,
                        "hbsName": "list",
                        "container": $("#tbody"),
                        "data": resultData,
                        "callback": function() {}
                    });
                }
            })
        },
        getHelpPersonList = function(sid, del) { //已选定的帮扶责任人结对信息
            mccms.ajax({ //通过责任人id数组查找帮扶责任人API
                "url": "/helppeson/findhelppesonMultiple",
                "cache": false,
                "method": "POST",
                "data": {
                    "sid": sid
                },
                "success": function(data) {
                    if (data.result) {
                        mccms.getHbs({
                            "local": true,
                            "hbsName": "helpList",
                            "container": $("#helpTobdy"),
                            "data": data,
                            "callback": function() {
                                if (del) {
                                    layer.msg("删除成功！")
                                } else {
                                    layer.msg("新增成功！")
                                }
                                mccms.pageHtml(data, getHelpPersonList, '');
                            }
                        });
                    } else {
                        mccms.getHbs({
                            "local": true,
                            "hbsName": "helpList",
                            "container": $("#helpTobdy"),
                            "data": '',
                            "callback": function() {}
                        });
                    }
                }
            })
        },
        subMemberMsg = function() { //家庭成员保存
            var data1 = {
                name: $('#name1').val(),
                number: $('#number').val(),
                idType: $('#idType').val(),
                birthTime: $('#birthTime').val(),
                nation: $('#nation').val(),
                culture: $('#culture').val(),
                healthy: $('#healthy').val(),
                soldier: $('#soldier').val(),
                province: $('#province2').val(),
                county: $('#county').val(),
                workTime: $('#workTime').val(),
                telephone: $('#telephone').val(),
                enterTime: $('#enterTime').val(),
                institution: $('#institution').val(),
                county: $('#county2').val(),
                sex: $('#sex').val(),
                idNumber: $('#idNumber').val(),
                relation: $('#relation').val(),
                number: $('#number').val(),
                political: $('#political').val(),
                school: $('#school').val(),
                labour: $('#labour').val(),
                low: $('#low').val(),
                city: $('#city2').val(),
                village: $('#village2').val(),
                company: $('#company').val(),
                large: $('#large').val(),
                schoolName: $('#schoolName').val(),
                major: $('#major').val(),
                isStudent: $('#isStudent').val(),
                doType: $("#doType").val()
            }
            if (id) {
                data1.fid = mccms.getHash('id'); //用户id
            }

            var checkboxMember = $('.checkbox-member input:checked') //选定的家庭成员
            if (checkboxMember.length >= 2) {
                layer.msg('只能单个修改')
                return false
            } else if (checkboxMember.length === 1) { //编辑保存时

                data1.id = checkboxMember.attr('id'); //家庭成员id
                data1.fid = checkboxMember.attr('attr-fid'); //贫困户id

                mccms.ajax({ //修改家庭成员API - 参数: 贫困户id
                    "url": "/poorFa/addOrUpdateFamily",
                    "cache": false,
                    "method": "POST",
                    "data": data1,
                    "success": function() {
                        var id = mccms.getHash('id'); //用户id
                        mccms.ajax({ //查询家庭成员API
                            "url": "/poorFa/getPoorFamily",
                            "cache": false,
                            "method": "POST",
                            "data": data1,
                            "success": function(data) {
                                $("#addFamilyMask").hide();
                                $('#mainContainer').removeClass('noScroll')

                                if (!id) { //刷新 -- 新增页面-编辑
                                    var familyM = $("#tbody input[type=checkbox]"); //家庭成员
                                    var familySid = []; //家庭成员id数组
                                    familyM.each(function() {
                                        familySid.push($(this).attr("id"))
                                    })
                                    familySid = familySid.join(",")

                                    mccms.ajax({ //家庭成员详情API - 参数sid: 家庭成员id数组  
                                        "url": "/poorFa/findFamily",
                                        "cache": false,
                                        "method": "POST",
                                        "data": {
                                            "sid": familySid
                                        },
                                        "success": function(data) {
                                            mccms.getHbs({
                                                "local": true,
                                                "hbsName": "list",
                                                "container": $("#tbody"),
                                                "data": data,
                                                "callback": function() {}
                                            });
                                        }
                                    })
                                } else { //刷新 -- 编辑页面-编辑
                                    getMemberList(id)
                                }

                            }
                        })
                    }
                })
            } else { //新增按钮-保存
                var addUrl = id ? "/poorFa/addOrUpdateFamily" : "/poorFa/addFamily"; //前者编辑页面时的新增按钮，后者新增页面时的新增按钮
                mccms.ajax({ //新增与修改家庭成员API - 参数: 贫困户id
                    "url": addUrl,
                    "cache": false,
                    "method": "POST",
                    "data": data1,
                    "success": function() {
                        //关闭弹窗
                        $("#addFamilyMask").hide();
                        $('#mainContainer').removeClass('noScroll')

                        //家庭成员列表刷新
                        getMemberList(id)
                    }
                })
            }
        },
        subMsg = function() { //保存贫困户
            //其他贫困原因多选
            var arr = []
            var otherArr = $('#other input:checked')
            for (var i = 0; i < otherArr.length; i++) {
                arr.push(otherArr[i].value)
            }

            //帮扶责任人多选
            var helpArr = $('#helpTobdy input[name=help]')
            var arr1 = []
            if (helpArr.length) {
                helpArr.each(function(i, item) {
                    arr1.push($(item).attr('id'))
                })
            }

            var valid = modelForm.valid();
            var data = {
                province: $('#province1').val(),
                city: $('#city1').val(),
                county: $('#county').val(),
                country: $('#country').val(),
                village: $('#village1').val(),
                number: $('#number1').val(),
                contact: $('#contact').val(),
                bank: $('#bank').val(),
                cardNumber: $('#cardNumber').val(),
                standard: $('#standard').val(),
                poverty: $('#poverty').val(),
                attribute: $('#attribute').val(),
                soldier: $('#soldier1').val(),
                vehicle: $('#vehicle').val(),
                room: $('#room').val(),
                company: $('#company1').val(),
                reason: $('#reason input:checked').val() ? $('#reason input:checked').val() : '',
                other: arr.join(','),
                cuedLand: $('#cuedLand').val(),
                irrigation: $('#irrigation').val(),
                woodLand: $('#woodLand').val(),
                farmLand: $('#farmLand').val(),
                fruit: $('#fruit').val(),
                forageGrass: $('#forageGrass').val(),
                waters: $('#waters').val(),
                production: $('#production').val(),
                cooperative: $('#cooperative').val(),
                distance: $('#distance').val(),
                type: $('#type').val(),
                housing: $('#housing').val(),
                life: $('#life').val(),
                difficulty: $('#difficulty').val(),
                security: $('#security').val(),
                danger: $('#danger').val(),
                level: $('#level').val(),
                fuel: $('#fuel').val(),
                toilet: $('#toilet').val(),
                wages: $('#wages').val(),
                operating: $('#operating').val(),
                property: $('#property').val(),
                transfer: $('#transfer').val(),
                planning: $('#planning').val(),
                low: $('#low1').val(),
                five: $('#five').val(),
                pension: $('#pension').val(),
                ecology: $('#ecology').val(),
                elses: $('#elses').val(),
                year: $('#year1').val(),
                expenses: $('#expenses').val(),
                income: $('#income').val(),
                perCapita: $('#perCapita').val(),
                alone: $('#alone').val(),
                twoGirl: $('#twoGirl').val(),
                familys: JSON.stringify(memberArr),
                persons: arr1 ? arr1.join(',') : ''
            }

            if (isEdit) { //isEdit==1 表示编辑
                var id = $('#tbody input').eq(0).attr("id")
                var poorViId = mccms.getHash('id') //贫困户id
                if (id) {
                    data.id = poorViId
                    var arr = []
                    $('#tbody input').each(function(i, item) {
                        arr[i] = Number($(item).attr('id'))
                    })
                    data.familys = JSON.stringify(arr)
                    data.addTime = addTime
                    valid &&
                        mccms.ajax({ //修改贫困户API
                            "url": "/poorFa/updatePoorFamily",
                            "cache": false,
                            "method": "POST",
                            "data": data,
                            "dataType": 'json',
                            "contentType": 'application/json',
                            "success": function() {
                                mccms.gobackFromEdit()
                            }
                        })
                } else {
                    layer.msg('请添加家庭成员')
                }

            } else { //isEdit 没有时表示新增
                var id = $('#tbody input').eq(0).attr("id")
                if (id) {
                    valid &&
                        mccms.ajax({ //新增贫困户API
                            "url": "/poorFa/addPoorFamily",
                            "cache": false,
                            "method": "POST",
                            "data": data,
                            "dataType": 'json',
                            "contentType": 'application/json',
                            "success": function() {
                                /*mccms.goBack()*/
                                mccms.goBack()
                            }
                        })
                } else {
                    layer.msg('请添加家庭成员')
                }

            }


        },
        getW = function(params) { //省市县乡村

            //省请求
            _ajaxW(0, function(data) {
                createOption(data, function(cryHtml) {
                    $(".province1").each(function(i, item) {
                        $(item).html(cryHtml)
                    })
                    //省判断选中
                    $('.province1').val(s_province)
                    if (s_province) {
                        $('#province1').attr('disabled', 'disabled')
                    }
                    //市请求
                    _ajaxW(1, function(data) {
                        createOption(data, function(cryHtml) {
                            $(".city").each(function(i, item) {
                                $(item).html(cryHtml)
                            })
                            //市判断选中
                            $('.city').val(s_city)
                            if (s_city) {
                                $('#city1').attr('disabled', 'disabled')
                            }
                            //县请求
                            _ajaxW(2, function(data) {
                                createOption(data, function(cryHtml) {
                                    $(".county").each(function(i, item) {
                                        $(item).html(cryHtml)
                                    })
                                    //县判断选中
                                    $('.county').val(s_cty)
                                    if (s_cty) {
                                        $('#county').attr('disabled', 'disabled')
                                    }
                                    //乡请求
                                    _ajaxW(3, function(data) {
                                        createOption(data, function(cryHtml) {
                                            $('#country').html(cryHtml)
                                            $('#country').val(s_cry)

                                            //村请求
                                            if (s_cry) {
                                                $('#country').attr('disabled', 'disabled')
                                            }
                                            if (params) {
                                                $('#province1').val(params.province)
                                                $('#city1').val(params.city)
                                                $('#county').val(params.county)
                                                $('#country').val(params.country)
                                            }
                                            var countryId = $('#country').find('option:checked').attr('id');
                                            if (params) {
                                                // s_cry_id = countryId
                                            }
                                            _ajaxW(countryId, function(data) {
                                                createOption(data, function(cryHtml) {
                                                    $("#village1").html(cryHtml);
                                                })
                                                $('.village1').val(s_name)
                                                if (s_name) {
                                                    $('#village1').attr('disabled', 'disabled')
                                                }
                                                if (params) {
                                                    $("#village1").val(params.village);
                                                }

                                                //村下拉
                                                $("#village1").change(function() {
                                                    village1Id = $(this).find("option:checked").attr("id");
                                                })

                                                var countryId = $('#country').find('option:checked').attr('id');
                                                if (params) {
                                                    /*s_cry_id = countryId*/
                                                }
                                                _ajaxW(countryId, function(data) {
                                                    createOption(data, function(cryHtml) {
                                                        $("#village1").html(cryHtml);
                                                    })
                                                    $('.village1').val(s_name)
                                                    if (s_name) {
                                                        $('#village1').attr('disabled', 'disabled')
                                                    }
                                                    if (params) {
                                                        $("#village1").val(params.village);
                                                    }
                                                    //村下拉
                                                    $("#village1").change(function() {
                                                        village1Id = $(this).find("option:checked").attr("id");
                                                    });
                                                })

                                            })
                                        })
                                    })
                                    if (s_cry) {
                                        $('#country').attr('disabled', 'disabled')
                                    } else {
                                        //乡下拉
                                        $("#country").change(function() {
                                            var countryId = $(this).find("option:checked").attr("id");
                                            //村请求
                                            _ajaxW(countryId, function(data) {
                                                createOption(data, function(cryHtml) {
                                                    $("#village1").html(cryHtml);
                                                })
                                            })
                                        });
                                    }
                                })
                            })
                        })
                    })
                })

                //省下拉
                $(".province1").change(function() {
                    var province1Id = $(this).find("option:checked").attr("id");
                    //市请求
                    _ajaxW(province1Id, function(data) {
                        createOption(data, function(cryHtml) {
                            // $("#city").html(cryHtml);
                            $(".city").each(function(i, item) {
                                $(item).html(cryHtml)
                            })
                        })
                    })
                    //市下拉
                    $(".city").change(function() {
                        var cityId = $(this).find("option:checked").attr("id");
                        //县请求
                        _ajaxW(cityId, function(data) {
                            createOption(data, function(cryHtml) {
                                // $("#county").html(cryHtml);
                                $(".county").each(function(i, item) {
                                    $(item).html(cryHtml)
                                })
                            })
                        })
                        //县下拉
                        $(".county").change(function() {
                            var countyId = $(this).find("option:checked").attr("id");
                            //乡请求
                            _ajaxW(countyId, function(data) {
                                createOption(data, function(cryHtml) {
                                    // $("#country").html(cryHtml);
                                    $(".country").each(function(i, item) {
                                        $(item).html(cryHtml)
                                    })
                                })
                            })
                            //乡下拉
                            $("#country").change(function() {
                                var countryId = $(this).find("option:checked").attr("id");


                                //村下拉
                                /*$("#village1").change(function() {
                                    village1Id = $(this).find("option:checked").attr("id");*/


                                //村请求
                                _ajaxW(countryId, function(data) {
                                    createOption(data, function(cryHtml) {
                                        $("#village1").html(cryHtml);
                                    })
                                })

                                //村下拉
                                $("#village1").change(function() {
                                    village1Id = $(this).find("option:checked").attr("id");
                                    getHelpPersonList();
                                });

                            });
                        });
                    });
                });
            })
        },
        _ajaxW = function(id, fn) { //地区请求
            mccms.ajax({
                "url": "/area/findarea",
                "cache": false,
                "method": "POST",
                "data": {
                    "fatherId": id
                },
                success: function(data) {
                    return fn(data)
                }
            });
        },
        createOption = function(data, fn) { //创造option
            var cryHtml = '<option value="">请选择</option>';
            for (var i = 0; i < data.result.length; i++) {
                cryHtml += '<option data-number="' + data.result[i].areaCode + '" id="' + data.result[i].id + '" value="' + data.result[i].area + '">' + data.result[i].area + '</option>';
            }
            return fn(cryHtml)
        }

    // 流程
    //家庭成员保存
    addMain.on('click', '#save1-btn', function() {
        subMemberMsg()
    })
    //全部保存
    addMain.on('click', '#save-btn', function() {
        myRequired("modelForm", "addPopup"); //必填提示

        subMsg()
    })
    //帮扶日志按钮
    addMain.on('click', "#helpLog-btn", function() { //帮扶
        var poorFamilyId = mccms.getHash('id') //用户ID
        mccms.goTo("povertyStrickenEdit", "visitingRecord", { "poorFamilyId": poorFamilyId, });
    })

    var memberArr = [];

    //进入主页面时先删除家庭成员列表
    mccms.ajax({ //删除家庭成员API
        "url": "/poorFa/deleteFamily",
        "cache": false,
        "method": "POST",
        "data": '',
        success: function(data) {}
    });

    //页面加载
    //operatedState==1为查看不可编辑,0为可编辑
    if (operatedState == 1) { //查看页面
        getDetail(id)
    }
    if (operatedState == 0) { //编辑页面
        getDetail(id, addTime)
    }
    if (!id) { //新增页面
        getDetail()
    }
}

/**
 * @submenu [结对查询]
 * @Method doubleInquire
 * @date 2017-11-16
 * @author Arthur - caiwen
 * @tips 此方法查询的是贫困户的信息
 */
/*--结对查询--*/
function doubleInquire() {
    // 变量声明
    var main = $('#mainCon'),
        cryVal = s_cry, //乡的选中
        nameVal = s_name, //村的选中
        pageNo = 1, //当前第1页
        pageSize = 10, //每页10行
        pageCount = null,
        getList = function(pageNo, pageSize, checkType) { //getList() 贫困户主页面渲染
            areaSelected(cryVal, nameVal, checkType, function() { //areaSelected() 权限控制方法
                mccms.ajax({ //贫困户列表API
                    "url": "/poorFa/getPoorFamilys",
                    "cache": false,
                    "method": "POST",
                    "data": $("#searchForm").serialize() + "&pageNo=" + pageNo + "&pageSize=" + pageSize,
                    "success": function(data) {
                        mccms.getHbs({
                            "local": true,
                            "hbsName": "list1",
                            "container": $("#tbody1"),
                            "data": data.result,
                            "callback": function() {
                                //分页方法
                                PagingMethods(pageNo, pageSize, data, getList);

                                //点击数据项添加背景色 
                                tdAddBg('tbody1')

                                //贫困户对应显示帮扶负责人
                                $("#tbody1 input").on("click", function() {
                                    var id = $('#tbody1 input[name=radio]:checked').attr("id"); //选定贫困户id   
                                    doubleInquireVShelpPersonLiable(id);
                                })

                                //改变td line-height
                                $("#tbody1 tr td").css("line-height", "27px")
                                //乡回显
                                $('#cry').change(function(event) {
                                    /* Act on the event */
                                    cryVal = $(this).find('option:selected').val() //获取乡选择，用于查询条件回显，若不获取，条件会被重置
                                })
                                //村回显
                                $('#name').change(function(event) {
                                    /* Act on the event */
                                    nameVal = $(this).find('option:selected').val() //获取村选择，用于查询条件回显，若不获取，条件会被重置
                                })

                            }
                        });
                    }
                })
            })
        }
    //乡和村下拉选择
    cryAndNameChange()
    //选择年度
    laydate.render({
        elem: '#year', 
        type: 'year'
    })
    ThisYear(); //当前年
    // 流程  
    main.on('click', '.queryBtn', function() { //查询
        getList(pageNo, pageSize, 'true')
    });
    main.on('click', ".export_btn", function() { //导出功能
        location.href = "poorFa/exportPoorFamilys?" + $("#searchForm").serialize();
    });
    getList(pageNo, pageSize);
}

/**
 * @submenu [贫困户 对应 帮扶负责人]
 * @Method doubleInquireVShelpPersonLiable
 * @date 2017-11-16
 * @author Arthur - caiwen
 * @tips 此方法查询的是贫困户 对应 帮扶负责人的信息
 */
/*--贫困户 对应 帮扶负责人--*/
function doubleInquireVShelpPersonLiable(id) {
    // 变量声明 
    var getList = function(pageNo) {
        if (!pageNo) { pageNo = 1 }
        mccms.ajax({ //贫困户对应帮扶负责人 API
            "url": "/poorFa/queryFamilyhelpperson?id=" + id,
            "cache": false,
            "method": "POST",
            "data": {
                "pageNo": pageNo,
                "pageSize": 10
            },
            "success": function(data) {
                mccms.getHbs({
                    "local": true,
                    "hbsName": "list2",
                    "container": $("#tbody2"),
                    "data": data,
                    "callback": function() {
                        //点击数据项添加背景色 
                        tdAddBg('tbody2')

                        //改变td line-height
                        $("#tbody2 tr td").css("line-height", "27px")
                    }
                });
                mccms.pageHtml(data, getList, [], "layPage2");

            }
        })
    };
    getList();
}

/**
 * ------------------------------------------------------------------
 * @project [fuping background management system]
 * @module statisticalTable - 统计报表模块
 * @date 2017-11-22 start
 * @author Arthur - caiwen
 * ------------------------------------------------------------------
 */

/**
 * @submenu [贫困村识别标准统计表]
 * @Method poorVilageStandardStatistics
 * @date 2017-11-22
 * @author Arthur - caiwen
 * @parameter $('#mainCon') 主页面容器
 * @parameter mainList 主页面hbs模板
 * @parameter $("#searchForm").serialize() 查询时表单序列化参数
 */
/*-- 贫困村识别标准统计表 --*/
function poorVilageStandardStatistics() {
    // 变量声明
    var main = $('#mainCon'),
        cryVal = s_cry, //乡的选中
        nameVal = s_name, //村的选中
        pageNo = 1, //当前第1页
        pageSize = 10, //每页10行
        pageCount = null,
        getList = function(pageNo, pageSize, checkType) { //getList() 主页面渲染
            areaSelected(cryVal, nameVal, checkType, function() { //areaSelected() 权限控制方法
                mccms.ajax({ //贫困村识别标准统计表查询API
                    "url": "/poorVi/poorVillageStatistics",
                    "cache": false,
                    "method": "POST",
                    "data": $("#searchForm").serialize() + "&pageNo=" + pageNo + "&pageSize=" + pageSize,
                    "success": function(data) {
                        mccms.getHbs({
                            "local": true,
                            "hbsName": "mainList",
                            "container": $("#tbody"),
                            "data": data.result,
                            "callback": function() {
                                //分页方法
                                PagingMethods(pageNo, pageSize, data, getList);

                                //点击数据项添加背景色
                                tdAddBg('tbody')
                            }
                        });
                    }
                })
            });
        };

    //时间插件初始化
    laydate.render({
        elem: '#year',
        type: 'year'
    })
    //乡和村下拉选择
    cryAndNameChange()

    // 流程  
    ThisYear(); //当前年
    main.on('click', '.queryBtn', function() { //查询
        getList(pageNo, pageSize, 'true')
    });
    main.on('click', ".export_btn", function() { //导出功能
        location.href = "poorVi/exportPoorVillageStatistics?" + $("#searchForm").serialize();
    });
    getList(pageNo, pageSize);

}

/**
 * @submenu [贫困村发展方向分类统计表]
 * @Method poorVilageDevelopmentclassStatistics
 * @date 2017-11-22
 * @author Arthur - caiwen
 * @parameter $('#mainCon') 主页面容器
 * @parameter mainList 主页面hbs模板
 * @parameter $("#searchForm").serialize() 查询时表单序列化参数
 */
/*-- 贫困村发展方向分类统计表 --*/
function poorVilageDevelopmentclassStatistics() {
    // 变量声明
    var main = $('#mainCon'),
        cryVal = s_cry, //乡的选中
        nameVal = s_name, //村的选中
        pageNo = 1, //当前第1页
        pageSize = 10, //每页10行
        pageCount = null,
        getList = function(pageNo, pageSize, checkType) { //getList() 主页面渲染
            areaSelected(cryVal, nameVal, checkType, function() { //areaSelected() 权限控制方法
                mccms.ajax({ //贫困村发展方向分类统计表查询API
                    "url": "/poorVi/poorVilageDevelopmentclass",
                    "cache": false,
                    "method": "POST",
                    "data": $("#searchForm").serialize() + "&pageNo=" + pageNo + "&pageSize=" + pageSize,
                    "success": function(data) {
                        mccms.getHbs({
                            "local": true,
                            "hbsName": "mainList",
                            "container": $("#tbody"),
                            "data": data.result,
                            "callback": function() {
                                //分页方法
                                PagingMethods(pageNo, pageSize, data, getList);

                                //点击数据项添加背景色
                                tdAddBg('tbody')
                            }
                        });
                    }
                })
            });
        };
    //时间插件初始化
    laydate.render({
        elem: '#year',
        type: 'year'
    })
    //乡和村下拉选择
    cryAndNameChange()

    // 流程  
    ThisYear(); //当前年
    main.on('click', '.queryBtn', function() { //查询
        getList(pageNo, pageSize, 'true')
    });
    main.on('click', ".export_btn", function() { //导出功能
        location.href = "poorVi/exportDevelopmentclass?" + $("#searchForm").serialize();
    });
    getList(pageNo, pageSize);
}

/**
 * @submenu [贫困村地形地貌分类统计表]
 * @Method poorVilageTerrainStatistics
 * @date 2017-11-22
 * @author Arthur - caiwen
 * @parameter $('#mainCon') 主页面容器
 * @parameter mainList 主页面hbs模板
 * @parameter $("#searchForm").serialize() 查询时表单序列化参数
 */
/*-- 贫困村地形地貌分类统计表 --*/
function poorVilageTerrainStatistics() {
    // 变量声明
    var main = $('#mainCon'),
        cryVal = s_cry, //乡的选中
        nameVal = s_name, //村的选中
        pageNo = 1, //当前第1页
        pageSize = 10, //每页10行
        pageCount = null,
        getList = function(pageNo, pageSize, checkType) { //getList() 主页面渲染
            areaSelected(cryVal, nameVal, checkType, function() { //areaSelected() 权限控制方法
                mccms.ajax({ //贫困村地形地貌分类统计表查询API
                    "url": "/poorVi/poorVilageLandformclass",
                    "cache": false,
                    "method": "POST",
                    "data": $("#searchForm").serialize() + "&pageNo=" + pageNo + "&pageSize=" + pageSize,
                    "success": function(data) {
                        mccms.getHbs({
                            "local": true,
                            "hbsName": "mainList",
                            "container": $("#tbody"),
                            "data": data.result,
                            "callback": function() {
                                //分页方法
                                PagingMethods(pageNo, pageSize, data, getList);

                                //点击数据项添加背景色
                                tdAddBg('tbody')
                            }
                        });
                    }
                })
            });
        };
    //时间插件初始化
    laydate.render({
        elem: '#year',
        type: 'year'
    })
    //乡和村下拉选择
    cryAndNameChange()

    // 流程  
    ThisYear(); //当前年
    main.on('click', '.queryBtn', function() { //查询
        getList(pageNo, pageSize, 'true')
    });
    main.on('click', ".export_btn", function() { //导出功能
        location.href = "poorVi/exportLandformclass?" + $("#searchForm").serialize();
    });
    getList(pageNo, pageSize);
}

/**
 * @submenu [贫困村村官和党员情况统计表]
 * @Method poorVilageOfficialPartyMembersStatistics
 * @date 2017-11-22
 * @author Arthur - caiwen
 * @parameter $('#mainCon') 主页面容器
 * @parameter mainList 主页面hbs模板
 * @parameter $("#searchForm").serialize() 查询时表单序列化参数
 */
/*-- 贫困村村官和党员情况统计表 --*/
function poorVilageOfficialPartyMembersStatistics() {
    // 变量声明
    var main = $('#mainCon'),
        cryVal = s_cry, //乡的选中
        nameVal = s_name, //村的选中
        pageNo = 1, //当前第1页
        pageSize = 10, //每页10行
        pageCount = null,
        getList = function(pageNo, pageSize, checkType) { //getList() 主页面渲染
            areaSelected(cryVal, nameVal, checkType, function() { //areaSelected() 权限控制方法
                mccms.ajax({ //贫困村村官和党员情况统计表查询API
                    "url": "/poorVi/poorVilageOfficialsAndMembers",
                    "cache": false,
                    "method": "POST",
                    "data": $("#searchForm").serialize() + "&pageNo=" + pageNo + "&pageSize=" + pageSize,
                    "success": function(data) {
                        mccms.getHbs({
                            "local": true,
                            "hbsName": "mainList",
                            "container": $("#tbody"),
                            "data": data.result,
                            "callback": function() {
                                //分页方法
                                PagingMethods(pageNo, pageSize, data, getList);

                                //点击数据项添加背景色
                                tdAddBg('tbody')
                            }
                        });
                    }
                })
            });
        };
    //时间插件初始化
    laydate.render({
        elem: '#year',
        type: 'year'
    })
    //乡和村下拉选择
    cryAndNameChange()

    // 流程  
    ThisYear(); //当前年
    main.on('click', '.queryBtn', function() { //查询
        getList(pageNo, pageSize, 'true')
    });
    main.on('click', ".export_btn", function() { //导出功能
        location.href = "poorVi/exportPoorVilageOfficialsAndMembers?" + $("#searchForm").serialize();
    });
    getList(pageNo, pageSize);
}

/**
 * @submenu [贫困村土地资源情况统计表]
 * @Method poorVilageLandStatistics
 * @date 2017-11-22
 * @author Arthur - caiwen
 * @parameter $('#mainCon') 主页面容器
 * @parameter mainList 主页面hbs模板
 * @parameter $("#searchForm").serialize() 查询时表单序列化参数
 */
/*-- 贫困村土地资源情况统计表 --*/
function poorVilageLandStatistics() {
    // 变量声明
    var main = $('#mainCon'),
        cryVal = s_cry, //乡的选中
        nameVal = s_name, //村的选中
        pageNo = 1, //当前第1页
        pageSize = 10, //每页10行
        pageCount = null,
        getList = function(pageNo, pageSize, checkType) { //getList() 主页面渲染
            areaSelected(cryVal, nameVal, checkType, function() { //areaSelected() 权限控制方法
                mccms.ajax({ //贫困村土地资源情况统计表查询API
                    "url": "/poorVi/poorVilageLand",
                    "cache": false,
                    "method": "POST",
                    "data": $("#searchForm").serialize() + "&pageNo=" + pageNo + "&pageSize=" + pageSize,
                    "success": function(data) {
                        mccms.getHbs({
                            "local": true,
                            "hbsName": "mainList",
                            "container": $("#tbody"),
                            "data": data.result,
                            "callback": function() {
                                //分页方法
                                PagingMethods(pageNo, pageSize, data, getList);

                                //点击数据项添加背景色
                                tdAddBg('tbody')
                            }
                        });
                    }
                })
            });
        };
    //时间插件初始化
    laydate.render({
        elem: '#year',
        type: 'year'
    })
    //乡和村下拉选择
    cryAndNameChange()

    // 流程  
    ThisYear(); //当前年
    main.on('click', '.queryBtn', function() { //查询
        getList(pageNo, pageSize, 'true')
    });
    main.on('click', ".export_btn", function() { //导出功能
        location.href = "poorVi/exportPoorVilageLand?" + $("#searchForm").serialize();
    });
    getList(pageNo, pageSize);
}